/*咬破发送的请求*/
/*枚举地址*/
import request from '@/utils/request.ts'
import {
  reqRoleMenuTreeData,
  responseRolePageDate,
} from '@/api/system/role/type.ts'
import { reqBaseData, reqTableData } from '@/api/type.ts'
import data from '@/views/system/dict/data.vue'

enum API {
  ROLE_LIST_URL = '/system/role/list' /*获取全部角色信息*/,
  ROLE_ADD_URL = '/system/role/add' /*添加角色信息*/,
  ROLE_EDIT_URL = '/system/role/edit' /*修改角色信息*/,
  ROLE_DELETE_URL = '/system/role/delete' /*删除角色信息*/,
  ROLE_CHANGE_STATUS_URL = '/system/role/changeStatus' /*修改角色状态*/,
  ROLE_GET_INFO_BY_ID_URL = '/system/role/getInfoById' /*根据角色id来获取角色信息*/,
  ROLE_MENU_TREE_URL = '/system/role/menuTree' /*获取菜单树信息*/,
  ROLE_AUTH_USER_ALLOCATED_LIST_URL = '/system/role/authUser/allocatedList' /*根据角色ID获取已分配该角色的用户列表*/,
  ROLE_AUTH_USER_UN_ALLOCATED_LIST_URL = '/system/role/authUser/unallocatedList' /*根据角色ID获取未分配该角色的用户列表*/,
  ROLE_AUTH_USER_SELECT_ALL_URL = '/system/role/authUser/selectAll' /*将角色分配给用户*/,
  ROLE_AUTH_USER_CANCEL_URL = '/system/role/authUser/cancel' /*cancel取消授权用户*/,
  ROLE_AUTH_USER_CANCEL_ALL_URL = '/system/role/authUser/cancelAll' /*批量取消授权用户*/,
}

/*进行分页查询获取全部的角色信息*/
export const reqRolePageList = (queryParams: any) => {
  return request<any, responseRolePageDate>({
    url: API.ROLE_LIST_URL,
    method: 'get',
    params: queryParams,
  })
}

/*添加角色信息*/
export const reqRoleAddUrl = (form: any) => {
  return request.post<any, any>(API.ROLE_ADD_URL, form)
}
/*修改角色信息*/
export const reqRoleEditUrl = (form: any) => {
  return request.put<any, reqBaseData>(API.ROLE_EDIT_URL, form)
}

/*删除角色信息*/
export const reqRoleDeleteUrl = (roleIds: any) => {
  return request.delete<any, reqBaseData>(API.ROLE_DELETE_URL + '/' + roleIds)
}

/*修改角色状态*/
export const reqRoleChangeStatusUrl = (form: any) => {
  return request.put<any, reqBaseData>(API.ROLE_CHANGE_STATUS_URL, form)
}

/*根据角色id来获取角色信息*/
export const reqGetInfoByIdUrl = (roleId: number) => {
  return request.get<any, any>(API.ROLE_GET_INFO_BY_ID_URL + '/' + roleId)
}

/*进行分页查询获取全部的角色信息*/
export const reqRoleMenuTreeUrl = () => {
  return request.get<any, reqRoleMenuTreeData>(API.ROLE_MENU_TREE_URL)
}

/*根据角色ID获取已经分配该角色的用户列表*/
export const reqRoleAuthUserAllocatedListUrL = (query: any) => {
  return request<any, reqTableData>({
    url: API.ROLE_AUTH_USER_ALLOCATED_LIST_URL,
    method: 'get',
    params: query,
  })
}

/*根据角色ID获取已经分配该角色的用户列表*/
export const reqRoleAuthUserUnAllocatedListUrl = (query: any) => {
  console.log(query)
  return request<any, reqTableData>({
    url: API.ROLE_AUTH_USER_UN_ALLOCATED_LIST_URL,
    method: 'get',
    params: query,
  })
}

/*修改用户的角色权限*/
export const reqAuthUserSelectAllUrl = (data: any) => {
  return request<any, reqBaseData>({
    url: API.ROLE_AUTH_USER_SELECT_ALL_URL,
    method: 'put',
    params: data,
  })
}

/*取消授权用户*/
export const reqRoleAuthUserCancelUrl = (data: any) => {
  return request.put<any, reqBaseData>(API.ROLE_AUTH_USER_CANCEL_URL, data)
}

/*批量取消授权用户*/
export const reqRoleAuthUserCancelAllUrl = (data: any) => {
  console.log(data)
  // return request.put<any, ResponseData>(API.ROLE_AUTH_USER_CANCEL_ALL_URL, data);
  return request<any, reqBaseData>({
    url: API.ROLE_AUTH_USER_CANCEL_ALL_URL,
    method: 'put',
    params: data,
  })
}

// 根据角色ID查询部门树结构
export function reqRoleDeptTreeSelect(roleId) {
  return request({
    url: '/system/role/deptTree/' + roleId,
    method: 'get'
  })
}



// 角色数据权限
export function reqRoleDataScope(data) {
  return request({
    url: '/system/role/dataScope',
    method: 'put',
    data: data
  })
}
